<template>
  <div id="orderRtx"
       v-loading="loading">
    <v-tableTitle :btnConfig="btnConfig"
                  :tableSelectData="tableSelectData"
                  :title="$t('out.forwarding')"
                  @del="del"
                  @newLogistics="newLogistics"
                  @newExpress="newExpress"></v-tableTitle>
    <v-table :pageSize="pageSize"
             :page="page"
             :tableConfig="tableConfig"
             :tableData="tableData"
             :total="total"
             @findData="getTableData"
             @getTableData="getTableData"
             @searhData="searhData"
             @selectData="selectData"
             @setdialog="setdialog"
             @upData="getTableData"
             ref="table"></v-table>
  </div>
</template>

<script type="text/ecmascript-6">
import tableTitle from "commons/TableTitle";
import table from "commons/Table";
import baseMixin from "@/mixins/BaseMixin";
import config from "./Config";

export default {
  name: "forwarding",
  mixins: [baseMixin, config],
  data() {
    return {
      loading: false,
      tableConfig: [
        {
          label: this.$t('out.shippingkey'),
          prop: "shippingkey",
          input: "input"
        },
        {
          label: this.$t('common.type'),
          prop: "type",
          input: "select",
          options: this.getOptions("querycodeLkup/RTXSHIPTYPE")
        },
        {
          label: this.$t('config.carrierCode'),
          prop: "carriercode",
          input: "select",
          options: this.getOptions("querycarriercodeDrowDown")
        },
        {
          label: this.$t('common.status'),
          prop: "status",
          input: "select",
          options: this.getOptions("querycodeLkup/RTXSHIPSTATUS")
        },
        {
          label: this.$t('out.ordernumber'),
          prop: "ordernumber",
          input: "input"
        },
        {
          label: this.$t('out.boxnumber'),
          prop: "boxnumber",
          input: "input"
        },
        {
          label: this.$t('app.addDate'),
          prop: "adddate",
          input: "date"
        },
        {
          label: this.$t('app.addName'),
          prop: "addwho",
          input: "input"
        },
        {
          label: this.$t('out.editDate'),
          prop: "editdate",
          input: "date"
        },
        {
          label: this.$t('app.editName'),
          prop: "editwho",
          input: "input"
        }
      ],
      tableData: [],
      page: 1,
      pageSize: 10,
      total: 10,
      tableSelectData: [],
      tableSearhData: {}
    };
  },
  computed: {
    btnConfig() {
      return [
        { label: this.$t('out.newLogistics'),certigier: !this.btnPermNameList.includes('WM020801'), invalid: "newLogistics" },
        { label: this.$t('out.newExpress'),certigier: !this.btnPermNameList.includes('WM020802'), invalid: "newExpress" },
        { label: this.$t('common.delete'),certigier: !this.btnPermNameList.includes('WM020803'), disabled: true, invalid: "del" }
      ];
    }
  },
  created() {
  },
  methods: {
    //新建物流
    async newLogistics() {
      let whseid = this.$store.state.wms;
      let opeuser = this.$Cookies.get('user');
      let name = "RTXSHIPWL";
      try {
        let res = await this.$api.get(`/getHttpUrl/${name}`);
        
          let url = `${res.bean}?whseid=${whseid}&opeuser=${opeuser}`;
          this.$router.push({ name: "iframe", params: { url: url, title: "新建物流" } });
        
      } catch (e) {
        this.$message.error(e);
      }
    },
    //新建快递
    async newExpress() {
      let whseid = this.$store.state.wms;
      let opeuser = this.$Cookies.get('user');
      let name = "RTXSHIPKD";
      try {
        let res = await this.$api.get(`/getHttpUrl/${name}`);
        
          let url = `${res.bean}?whseid=${whseid}&opeuser=${opeuser}`;
          // let url = `http://localhost:8086/rtxext/SHIPKD?whseid=wmwhse1&opeuser=panda`;
          this.$router.push({ name: "iframe", params: { url: url, title: "新建快递" } });
        
      } catch (e) {
        this.$message.error(e);
      }
    },
    //删除
    async del(data) {
      try {
        let res = await this.$api.post(`/deleteRtxShip`, data);
        
          this.$message.success(res.returnMgr);
          let page = sessionStorage.getItem("page");
          this.getTableData(page, this.tableSearhData);
        
      } catch (e) {
        this.$message.error(e);
      } finally {
        
      }
    },
    //选中的内容
    selectData(data) {
      this.tableSelectData = data;
    },
    async getTableData(page, data) {
      try {
        this.loading = true;
        let res = await this.$api.post(`/queryRtxShip/${page}`, data);
        
          this.tableData = res.page.list;
          this.page = res.page.curpage;
          this.pageSize = res.page.pageSize;
          this.total = res.page.total;
        
      } catch (e) {
        this.$message.error(e);
      } finally {
        this.loading = false;
      }
    },
    //搜索的值
    searhData(data, up) {
      if (!up) {
        this.tableSearhData = data;
      } else {
        this.tableSearhData = data;
        this.getTableData(1, this.tableSearhData);
      }
    },
    //设置弹框
    async setdialog(data) {
      let whseid = this.$store.state.wms;
      let opeuser = this.$Cookies.get('user');
      let type = data.type;
      let shippingkey = data.shippingkey;
      let carriercode = data.carriercode;
      let sttus = data.status;
      let name;
      let desc;
      if (type == "WL") {
        name = "RTXSHIPWL";
        desc = "物流编辑";
      } else {
        name = "RTXSHIPKD";
        desc = "快递编辑";
      }


      try {
        let res = await this.$api.get(`/getHttpUrl/${name}`);
        
          let url = `${res.bean}?whseid=${whseid}&opeuser=${opeuser}&shippingkey=${shippingkey}&carriercode=${carriercode}&status=${status}`;
          this.$router.push({ name: "iframe", params: { url: url, title: desc }});
        
      } catch (e) {
        this.$message.error(e);
      }


    }
  },
  mounted() {
    // ;
    this.$store.commit("setSkip", {});
    this.$store.commit("setRouteId", "");
    this.$store.commit("setNewFlag", false);
    this.$store.commit("setRouteData", {});
    this.$store.commit("setTemporary", "");
    this.getTableData(1, {});
  },
  watch: {
    tableSelectData(data) {
      if (this.permissionStatus) {
        if (data.length > 0) {
          this.deleteStatus = this.downloadStatus = false;
          this.allocationStatus = this.fafangStatus = false;
          this.deliverStatus = this.allPickStatus = this.allShipStatus = false;
        } else {
          this.deleteStatus = this.downloadStatus = true;
          this.allocationStatus = this.fafangStatus = true;
          this.deliverStatus = this.allPickStatus = this.allShipStatus = true;
        }
      }
    }
  },
  components: {
    "v-tableTitle": tableTitle,
    "v-table": table
  }
};
</script>

<style scoped>
#Orders {
  width: 100%;
  height: 99%;
  padding-top: 6px;
}
</style>
